package com.nfit.web.alluser;

import com.nfit.entity.AdminUser;
import com.nfit.entity.AllUser;
import com.nfit.entity.vo.ResponeVo;
import com.nfit.service.AllUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AllUserController {
    @Autowired
    private AllUserService service;
    @RequestMapping("/AllUser/all")
    public ResponeVo all() {
        List<AllUser> users = service.selectAll();
        if (users == null) {
            return ResponeVo.fail("暂无数据");
        }
        return ResponeVo.success(users);
    }

    @RequestMapping("AllUser/selectAllUserById")
    public ResponeVo selectTransactionById(String userId) {
        AllUser user = service.selectAllUserById(userId);
        if (user == null) {
            return ResponeVo.fail("暂无数据");
        }
        return ResponeVo.success(user);
    }

    @RequestMapping("AllUser/update")
    public ResponeVo updateAdminUser(@RequestBody AllUser user) {
        int result = service.updateAllUser(user);
        if (result == 0) {
            return ResponeVo.fail("更新失败");
        }
        return ResponeVo.success(user);
    }

    @RequestMapping("AllUser/delete")
    public ResponeVo deleteAllUserById(String userId) {
        int result = service.deleteAllUserById(userId);
        if (result == 0) {
            return ResponeVo.fail("删除失败");
        }
        return ResponeVo.success("删除成功");
    }

}
